/// 商品分类模型 - Product Category Model
class ProductCategory {
  /// 分类ID - Category ID
  final String id;
  
  /// 分类名称 - Category name
  final String name;
  
  /// 分类描述 - Category description
  final String description;
  
  /// 分类图标 - Category icon
  final String icon;
  
  /// 是否激活 - Whether it's active
  final bool isActive;
  
  /// 排序顺序 - Sort order
  final int sortOrder;
  
  /// 创建时间 - Created at
  final DateTime createdAt;
  
  /// 更新时间 - Updated at
  final DateTime updatedAt;

  const ProductCategory({
    required this.id,
    required this.name,
    required this.description,
    required this.icon,
    this.isActive = true,
    this.sortOrder = 0,
    required this.createdAt,
    required this.updatedAt,
  });

  /// 从JSON创建ProductCategory实例 - Create ProductCategory instance from JSON
  factory ProductCategory.fromJson(Map<String, dynamic> json) {
    return ProductCategory(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      description: json['description'] ?? '',
      icon: json['icon'] ?? '',
      isActive: json['is_active'] ?? true,
      sortOrder: json['sort_order'] ?? 0,
      createdAt: json['created_at'] != null 
          ? DateTime.parse(json['created_at']) 
          : DateTime.now(),
      updatedAt: json['updated_at'] != null 
          ? DateTime.parse(json['updated_at']) 
          : DateTime.now(),
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'description': description,
      'icon': icon,
      'is_active': isActive,
      'sort_order': sortOrder,
      'created_at': createdAt.toIso8601String(),
      'updated_at': updatedAt.toIso8601String(),
    };
  }
}